package com.im.service;

import com.im.dao.StaffDao;
import com.im.pojo.Staff;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class StaffSrvImpl implements StaffService{
    @Autowired
    private StaffDao staffDao;
    @Override
    public int save(Staff staff) {
        int num=0;
        String uuid= UUID.randomUUID().toString().replace("-","");
        staff.setId(uuid);
        List list_dept=staffDao.queryAllDept();
        List list_job=staffDao.queryAllJob();
        if((list_job!=null && list_job.size()>0)&&(list_dept!=null && list_dept.size()>0)) {
            num = staffDao.save(staff);
        }
        return num;
    }

    @Override
    public int delete(Staff staff) {
        staff.setIsDel(1);
        return staffDao.deleteById(staff);
    }

    @Override
    public int update(Staff staff) {
        return staffDao.updateById(staff);
    }

    @Override
    public Staff query(Staff staff) {
        staff=staffDao.queryById(staff);
        return staff;
    }
    @Override
    public List querydept() {
        List list=staffDao.queryAllDept();
        return list;
    }
    @Override
    public List queryjob() {
        List list=staffDao.queryAllJob();
        return list;
    }


    @Override
    public List queryAll(Staff staff) {
        if (staff.getName() != null && !"".equals(staff.getName())) {//java中判断是不是字符串!"".equals(column.getName())XML里判断是不是字符串and name!=''
            staff.setName("%"+staff.getName()+"%");
        }
        List list=staffDao.queryAll(staff);
        return list;
    }


}
